import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class NGuessNumber {
    /**
     * 随机生成4个 0-9 的随机数
     */
        public List<Integer> generateAnswer(){
            //创建集合获取生成的随机数
            List<Integer> list=new ArrayList<>();
           int a =0;
            while (a<4){
                boolean b=true;
                //创建随机数
                int random=(int) (Math.random()*10);
                for (int i = 0; i <list.size() ; i++) {
                    if (random ==list.get(i)){
                        b=false;
                        break;
                    }
                }
                if (b){
                    list.add(random);
                    a++;
                }
            }
            return list;
        }

    /**
     * 接收用户输入的数字
     */
    public List<Integer> getPlayerInput(){
        Scanner sc = new Scanner(System.in);
        List<Integer> userList = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            userList.add(sc.nextInt());
        }
        return userList;
    }

    /**
     * 比较后返回信息
     */
    public int compareGuessAnswer(List<Integer> list,List<Integer> userList){
        int a=0,b=0;
        for (int i = 0; i < list.size(); i++) {
            for (int j = 0; j < userList.size(); j++) {
                if(list.get(i)==userList.get(j)){
                    if (i==j)a++;
                    else b++;
                }
            }

        }
        if (a<4){
            System.out.println("A "+a+" B "+b);
        }
        return a;
    }

    /**
     * 判断是否胜利
     */
    public boolean isWin (int a){
        if (a==4){
            System.out.println("恭喜您游戏胜利");
            return true;
        }
        return false;
    }

    /**
     * 程序主方法
     */
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        NGuessNumber ng = new NGuessNumber();

        while (true){
        boolean end =false;
        List<Integer> computerList = ng.generateAnswer();
        System.out.println("请输入你猜测的四位数");

        while (!end){

         List<Integer> userList = ng.getPlayerInput();
         int a = ng.compareGuessAnswer(computerList,userList);
         end = ng.isWin(a);

        }
            System.out.println("是否继续游戏 Y继续 N放弃");
            String userstr =scanner.next();
            if ("N".equals(userstr)||"n".equals(userstr)){
                break;
            }
    }}
    }

